package com.ruoyi.frontuser.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.frontuser.domain.Frontnote;
import com.ruoyi.frontuser.service.IFrontnoteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 外出记录Controller
 * 
 * @author lbb
 * @date 2022-09-22
 */
@RestController
@RequestMapping("/frontuser/frontnote")
public class FrontnoteController extends BaseController
{
    @Autowired
    private IFrontnoteService frontnoteService;

    /**
     * 查询外出记录列表
     */
    @PreAuthorize("@ss.hasPermi('frontuser:frontnote:list')")
    @GetMapping("/list")
    public TableDataInfo list(Frontnote frontnote)
    {
        startPage();
        List<Frontnote> list = frontnoteService.selectFrontnoteList(frontnote);
        return getDataTable(list);
    }

    /**
     * 导出外出记录列表
     */
    @PreAuthorize("@ss.hasPermi('frontuser:frontnote:export')")
    @Log(title = "外出记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Frontnote frontnote)
    {
        List<Frontnote> list = frontnoteService.selectFrontnoteList(frontnote);
        ExcelUtil<Frontnote> util = new ExcelUtil<Frontnote>(Frontnote.class);
        util.exportExcel(response, list, "外出记录数据");
    }

    /**
     * 获取外出记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('frontuser:frontnote:query')")
    @GetMapping(value = "/{trid}")
    public AjaxResult getInfo(@PathVariable("trid") Long trid)
    {
        return AjaxResult.success(frontnoteService.selectFrontnoteByTrid(trid));
    }

    /**
     * 新增外出记录
     */
    @PreAuthorize("@ss.hasPermi('frontuser:frontnote:add')")
    @Log(title = "外出记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Frontnote frontnote)
    {
        return toAjax(frontnoteService.insertFrontnote(frontnote));
    }

    /**
     * 修改外出记录
     */
    @PreAuthorize("@ss.hasPermi('frontuser:frontnote:edit')")
    @Log(title = "外出记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Frontnote frontnote)
    {
        return toAjax(frontnoteService.updateFrontnote(frontnote));
    }

    /**
     * 删除外出记录
     */
    @PreAuthorize("@ss.hasPermi('frontuser:frontnote:remove')")
    @Log(title = "外出记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trids}")
    public AjaxResult remove(@PathVariable Long[] trids)
    {
        return toAjax(frontnoteService.deleteFrontnoteByTrids(trids));
    }
}
